package com.meraklisina.latexeditor;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Language {

	public String SaveAs;
	public String Save;
	public String File;
	public String Edit;
	public String Toolbar;
	public String New;
	public String LatexWizard;
	public String Open;
	public String Close;
	public String Exit;
	public String Undo;
	public String Redo;
	public String Copy;
	public String Paste;
	public String Cut;
	public String FindReplace;
	public String GoToLine;
	public String ConfigurationMenu;
	public String Customize;
	public String Create;
	public String CustomizeToolbars;
	public String TemplateCreatorWizard;
	public String Bold;
	public String Italic;
	public String Underline;
	public String FootNote;
	public String HyperLink;
	public String AlignLeft;
	public String AlignRight;
	public String AlignCenter;
	public String CommentIn;
	public String CommentOut;
	public String CreateToolbar;
	public String ConvertTo;
	public String Preview;
	public String PreviewSelected;
	public String Output;
	public String CreateNewFile;
	public String OpenWizardMenu;
	public String OpenExistingFile;
	public String CopySelection;
	public String CutSelection;
	public String SetMiktexPath;
	public String SaveAndExit;
	public String Cancel;
	public String MiktexPath;
	public String EnableOnTheFlyCompilation;
	public String LanguageSelection;
	public String Yes;
	public String No;
	public String GoTo;
	public String LineNumber;
	public String ActionButtonName;
	public String ToolTip;
	public String Prefix;
	public String Suffix;
	public String ExampleCommand;
	public String ActionButtonConfiguration;
	public String Add;
	public String FindNext;
	public String Replace;
	public String ReplaceAll;
	public String FindWhat;
	public String ReplaceWith;
	public String Direction;
	public String Up;
	public String Down;
	public String Import;
	public String Export;
	public String ExportDialogTittle1;
	public String ExportDialogTittle2;
	public String ImportDialogTittle;
	public String NoProposals;
	public String Info;
	public String ToolbarImported;
	
	
	public void LoadLanguage(String LanguageType)
	{
		XmlHandler ConfigurationHandler;
		
		if(BlueLatexEditor._operatingSystem.contains("Windows"))
			ConfigurationHandler = new XmlHandler("lang\\" + LanguageType + ".xml");
		else
			ConfigurationHandler = new XmlHandler("lang/" + LanguageType + ".xml");
    	
    	NodeList lang = ConfigurationHandler.GetElementsByTagName("LanguageVariables");
    	
    	int a = lang.getLength();
    	if (a < 1)
    		return;
    	
    	Node Variables = lang.item(0);
    	SaveAs = (ConfigurationHandler.GetChildNodeValue(Variables, "SaveAs"));
    	Save = ConfigurationHandler.GetChildNodeValue(Variables, "Save");
    	File = ConfigurationHandler.GetChildNodeValue(Variables, "File");
    	Edit = ConfigurationHandler.GetChildNodeValue(Variables, "Edit");
    	Toolbar = ConfigurationHandler.GetChildNodeValue(Variables, "Toolbar");
    	New = ConfigurationHandler.GetChildNodeValue(Variables, "New");
    	LatexWizard = ConfigurationHandler.GetChildNodeValue(Variables, "LatexWizard");
    	Open = ConfigurationHandler.GetChildNodeValue(Variables, "Open");
    	Close = ConfigurationHandler.GetChildNodeValue(Variables, "Close");
    	Exit = ConfigurationHandler.GetChildNodeValue(Variables, "Exit");
    	Undo = ConfigurationHandler.GetChildNodeValue(Variables, "Undo");
    	Redo = ConfigurationHandler.GetChildNodeValue(Variables, "Redo");
    	Copy = ConfigurationHandler.GetChildNodeValue(Variables, "Copy");
    	Paste = ConfigurationHandler.GetChildNodeValue(Variables, "Paste");
    	Cut = ConfigurationHandler.GetChildNodeValue(Variables, "Cut");
    	FindReplace = ConfigurationHandler.GetChildNodeValue(Variables, "FindReplace");
    	GoToLine = ConfigurationHandler.GetChildNodeValue(Variables, "GoToLine");
    	ConfigurationMenu = ConfigurationHandler.GetChildNodeValue(Variables, "ConfigurationMenu");
    	Customize = ConfigurationHandler.GetChildNodeValue(Variables, "Customize");
    	Create = ConfigurationHandler.GetChildNodeValue(Variables, "Create");
		CustomizeToolbars = ConfigurationHandler.GetChildNodeValue(Variables, "CustomizeToolbars");
		TemplateCreatorWizard = ConfigurationHandler.GetChildNodeValue(Variables, "TemplateCreatorWizard");
		Bold = ConfigurationHandler.GetChildNodeValue(Variables, "Bold");
		Italic = ConfigurationHandler.GetChildNodeValue(Variables, "Italic");
		Underline = ConfigurationHandler.GetChildNodeValue(Variables, "Underline");
		FootNote = ConfigurationHandler.GetChildNodeValue(Variables, "FootNote");
		HyperLink = ConfigurationHandler.GetChildNodeValue(Variables, "HyperLink");
		AlignLeft = ConfigurationHandler.GetChildNodeValue(Variables, "AlignLeft");
		AlignRight = ConfigurationHandler.GetChildNodeValue(Variables, "AlignRight");
		AlignCenter = ConfigurationHandler.GetChildNodeValue(Variables, "AlignCenter");
		CommentIn = ConfigurationHandler.GetChildNodeValue(Variables, "CommentIn");
		CommentOut = ConfigurationHandler.GetChildNodeValue(Variables, "CommentOut");
		CreateToolbar = ConfigurationHandler.GetChildNodeValue(Variables, "CreateToolbar");
		ConvertTo = ConfigurationHandler.GetChildNodeValue(Variables, "ConvertTo");
		Preview = ConfigurationHandler.GetChildNodeValue(Variables, "Preview");
		PreviewSelected = ConfigurationHandler.GetChildNodeValue(Variables, "PreviewSelected");
		Output = ConfigurationHandler.GetChildNodeValue(Variables, "Output");
		CreateNewFile = ConfigurationHandler.GetChildNodeValue(Variables, "CreateNewFile");
		OpenWizardMenu = ConfigurationHandler.GetChildNodeValue(Variables, "OpenWizardMenu");
		OpenExistingFile = ConfigurationHandler.GetChildNodeValue(Variables, "OpenExistingFile");
		CopySelection  = ConfigurationHandler.GetChildNodeValue(Variables, "CopySelection");
		CutSelection = ConfigurationHandler.GetChildNodeValue(Variables, "CutSelection");
		SetMiktexPath = ConfigurationHandler.GetChildNodeValue(Variables, "SetMiktexPath");
		SaveAndExit = ConfigurationHandler.GetChildNodeValue(Variables, "SaveAndExit");
		Cancel = ConfigurationHandler.GetChildNodeValue(Variables, "Cancel");
		MiktexPath = ConfigurationHandler.GetChildNodeValue(Variables, "MiktexPath");
		EnableOnTheFlyCompilation = ConfigurationHandler.GetChildNodeValue(Variables, "EnableOnTheFlyCompilation");
		LanguageSelection = ConfigurationHandler.GetChildNodeValue(Variables, "LanguageSelection");
		Yes = ConfigurationHandler.GetChildNodeValue(Variables, "Yes");
		No = ConfigurationHandler.GetChildNodeValue(Variables, "No");
		GoTo = ConfigurationHandler.GetChildNodeValue(Variables, "GoTo");
		LineNumber = ConfigurationHandler.GetChildNodeValue(Variables, "LineNumber");
		ActionButtonName = ConfigurationHandler.GetChildNodeValue(Variables, "ActionButtonName");
		ToolTip = ConfigurationHandler.GetChildNodeValue(Variables, "ToolTip");
		Prefix = ConfigurationHandler.GetChildNodeValue(Variables, "Prefix");
		Suffix = ConfigurationHandler.GetChildNodeValue(Variables, "Suffix");
		ExampleCommand = ConfigurationHandler.GetChildNodeValue(Variables, "ExampleCommand");
		ActionButtonConfiguration = ConfigurationHandler.GetChildNodeValue(Variables, "ActionButtonConfiguration");
		Add = ConfigurationHandler.GetChildNodeValue(Variables, "Add");
		FindNext = ConfigurationHandler.GetChildNodeValue(Variables, "FindNext");
		Replace = ConfigurationHandler.GetChildNodeValue(Variables, "Replace");
		ReplaceAll = ConfigurationHandler.GetChildNodeValue(Variables, "ReplaceAll");
		FindWhat = ConfigurationHandler.GetChildNodeValue(Variables, "FindWhat");
		ReplaceWith = ConfigurationHandler.GetChildNodeValue(Variables, "ReplaceWith");
		Direction = ConfigurationHandler.GetChildNodeValue(Variables, "Direction");
		Up = ConfigurationHandler.GetChildNodeValue(Variables, "Up");
		Down = ConfigurationHandler.GetChildNodeValue(Variables, "Down");
		Import = ConfigurationHandler.GetChildNodeValue(Variables, "Import");
		Export = ConfigurationHandler.GetChildNodeValue(Variables, "Export");
		ExportDialogTittle1 = ConfigurationHandler.GetChildNodeValue(Variables, "ExportDialogTittle1");
		ExportDialogTittle2 = ConfigurationHandler.GetChildNodeValue(Variables, "ExportDialogTittle2");
		ImportDialogTittle = ConfigurationHandler.GetChildNodeValue(Variables, "ImportDialogTittle");
		NoProposals = ConfigurationHandler.GetChildNodeValue(Variables, "NoProposals");
		Info = ConfigurationHandler.GetChildNodeValue(Variables, "Info");
		ToolbarImported = ConfigurationHandler.GetChildNodeValue(Variables, "ToolbarImported");
	}
	
	public void CreateLanguageFile() {
		 
        Document domDoc = XmlHandler.createXmlDocument() ;
        
        Element Variables = domDoc.createElement("Language");
        
        Element VariableElements = domDoc.createElement("LanguageVariables") ;
        
        Element SaveAs = domDoc.createElement("SaveAs");
        Element Save = domDoc.createElement("Save");
        Element File = domDoc.createElement("File");
        Element Edit = domDoc.createElement("Edit");
        Element Toolbar = domDoc.createElement("Toolbar");
        Element New = domDoc.createElement("New");
        Element LatexWizard = domDoc.createElement("LatexWizard");
        Element Open = domDoc.createElement("Open");
        Element Close = domDoc.createElement("Close");
        Element Exit = domDoc.createElement("Exit");
        Element Undo = domDoc.createElement("Undo");
        Element Redo = domDoc.createElement("Redo");
        Element Copy = domDoc.createElement("Copy");
        Element Paste = domDoc.createElement("Paste");
        Element Cut = domDoc.createElement("Cut");
        Element FindReplace = domDoc.createElement("FindReplace");
        Element GoToLine = domDoc.createElement("GoToLine");
        Element ConfigurationMenu = domDoc.createElement("ConfigurationMenu");
        Element Customize = domDoc.createElement("Customize");
        Element Create = domDoc.createElement("Create");
        Element CustomizeToolbars = domDoc.createElement("CustomizeToolbars");
        Element TemplateCreatorWizard = domDoc.createElement("TemplateCreatorWizard");
        Element Bold = domDoc.createElement("Bold");
        Element Italic = domDoc.createElement("Italic");
        Element Underline = domDoc.createElement("Underline");
        Element FootNote = domDoc.createElement("FootNote");
        Element HyperLink = domDoc.createElement("HyperLink");
        Element AlignLeft = domDoc.createElement("AlignLeft");
        Element AlignRight = domDoc.createElement("AlignRight");
        Element AlignCenter = domDoc.createElement("AlignCenter");
        Element CommentIn = domDoc.createElement("CommentIn");
        Element CommentOut = domDoc.createElement("CommentOut");
        Element CreateToolbar = domDoc.createElement("CreateToolbar");
        Element ConvertTo = domDoc.createElement("ConvertTo");
        Element Preview = domDoc.createElement("Preview");
        Element PreviewSelected = domDoc.createElement("PreviewSelected");
        Element Output = domDoc.createElement("Output");
        Element CreateNewFile = domDoc.createElement("CreateNewFile");
        Element OpenWizardMenu = domDoc.createElement("OpenWizardMenu");
        Element OpenExistingFile = domDoc.createElement("OpenExistingFile");
        Element CopySelection = domDoc.createElement("CopySelection");
        Element CutSelection = domDoc.createElement("CutSelection");
        Element SetMiktexPath = domDoc.createElement("SetMiktexPath");
    	Element SaveAndExit = domDoc.createElement("SaveAndExit");
    	Element Cancel = domDoc.createElement("Cancel");
    	Element MiktexPath = domDoc.createElement("MiktexPath");
    	Element EnableOnTheFlyCompilation = domDoc.createElement("EnableOnTheFlyCompilation");
    	Element LanguageSelection = domDoc.createElement("LanguageSelection");
    	Element Yes = domDoc.createElement("Yes");
    	Element No  = domDoc.createElement("No");
    	Element GoTo = domDoc.createElement("GoTo");
    	Element LineNumber = domDoc.createElement("LineNumber");
    	Element ActionButtonName = domDoc.createElement("ActionButtonName");
    	Element ToolTip = domDoc.createElement("ToolTip");
    	Element Prefix = domDoc.createElement("Prefix");
    	Element Suffix = domDoc.createElement("Suffix");
    	Element ExampleCommand = domDoc.createElement("ExampleCommand");
    	Element ActionButtonConfiguration = domDoc.createElement("ActionButtonConfiguration");
    	Element Add = domDoc.createElement("Add");
    	Element FindNext = domDoc.createElement("FindNext");
    	Element Replace = domDoc.createElement("Replace");
    	Element ReplaceAll = domDoc.createElement("ReplaceAll");
    	Element FindWhat = domDoc.createElement("FindWhat");
    	Element ReplaceWith = domDoc.createElement("ReplaceWith");
    	Element Direction = domDoc.createElement("Direction");
    	Element Up = domDoc.createElement("Up");
    	Element Down = domDoc.createElement("Down");
    	Element Import = domDoc.createElement("Import");
    	Element Export = domDoc.createElement("Export");
    	Element ExportDialogTittle1 = domDoc.createElement("ExportDialogTittle1");
    	Element ExportDialogTittle2 = domDoc.createElement("ExportDialogTittle2");
    	Element ImportDialogTittle = domDoc.createElement("ImportDialogTittle");
    	Element NoProposals = domDoc.createElement("NoProposals");
    	Element Info = domDoc.createElement("Info");
    	Element ToolbarImported = domDoc.createElement("ToolbarImported");
        
        Save.setTextContent("Save");
        SaveAs.setTextContent("Save As");
        File.setTextContent("File");
        Edit.setTextContent("Edit");
        Toolbar.setTextContent("Toolbar");
        New.setTextContent("New");
        LatexWizard.setTextContent("Latex Wizard");
        Open.setTextContent("Open");
        Close.setTextContent("Close");
        Exit.setTextContent("Exit");
        Exit.setTextContent("Exit");
        Undo.setTextContent("Undo");
        Redo.setTextContent("Redo");
        Copy.setTextContent("Copy");
        Paste.setTextContent("Paste");
        Cut.setTextContent("Cut");
        FindReplace.setTextContent("Find and Replace");
        GoToLine.setTextContent("Go To Line");
        ConfigurationMenu.setTextContent("Configuration Menu");
        Customize.setTextContent("Customize");
        Create.setTextContent("Create");
        CustomizeToolbars.setTextContent("Customize Toolbars");
        TemplateCreatorWizard.setTextContent("Template Creator Wizard");
        Bold.setTextContent("Bold");
        Italic.setTextContent("Italic");
        Underline.setTextContent("Underline");
        FootNote.setTextContent("FootNote");
        HyperLink.setTextContent("HyperLink");
        AlignLeft.setTextContent("Align Left");
        AlignRight.setTextContent("Align Right");
        AlignCenter.setTextContent("Align Center");
        CommentIn.setTextContent("Comment In");
        CommentOut.setTextContent("Comment Out");
        CreateToolbar.setTextContent("Create Toolbar");
        ConvertTo.setTextContent("Convert To");
        Preview.setTextContent("Preview");
        PreviewSelected.setTextContent("Preview Selected");
        Output.setTextContent("Output");
        CreateNewFile.setTextContent("Create New File");
        OpenWizardMenu.setTextContent("Open Wizard Menu");
        OpenExistingFile.setTextContent("Open Existing File");
        CopySelection.setTextContent("Copy Selection");
        CutSelection.setTextContent("Cut Selection");
        SetMiktexPath.setTextContent("Set Miktex Path");
    	SaveAndExit.setTextContent("Save & Exit");
    	Cancel.setTextContent("Cancel");
    	MiktexPath.setTextContent("Miktex Path (Windows)");
    	EnableOnTheFlyCompilation.setTextContent("Enable On The Fly Compilation");
    	LanguageSelection.setTextContent("Language Selection");
    	Yes.setTextContent("Yes");
    	No.setTextContent("No");
        GoTo.setTextContent("Go To");
        LineNumber.setTextContent("Line Number");
        ActionButtonName.setTextContent("Action Button Name");
    	ToolTip.setTextContent("Tool Tip");
    	Prefix.setTextContent("Prefix");
    	Suffix.setTextContent("Suffix");
    	ExampleCommand.setTextContent("Example Command");
    	ActionButtonConfiguration.setTextContent("Action Button Configuration");
    	Add.setTextContent("Add");
    	FindNext.setTextContent("Find Next");
		Replace.setTextContent("Replace");
		ReplaceAll.setTextContent("Replace All");
		FindWhat.setTextContent("Find What");
		ReplaceWith.setTextContent("Replace With");
		Direction.setTextContent("Direction");
		Up.setTextContent("Up");
		Down.setTextContent("Down");
		Import.setTextContent("Import");
		Export.setTextContent("Export");
		ExportDialogTittle1.setTextContent("Please choose folder to export");
		ExportDialogTittle2.setTextContent("Please choose destination folder");
		ImportDialogTittle.setTextContent("Please choose folder to import");
		NoProposals.setTextContent("No Proposals");
		Info.setTextContent("Info");
		ToolbarImported.setTextContent("Toolbar Imported");
        
        VariableElements.appendChild(Save);
        VariableElements.appendChild(SaveAs);
        VariableElements.appendChild(File);
        VariableElements.appendChild(Edit);
        VariableElements.appendChild(Toolbar);
        VariableElements.appendChild(New);
        VariableElements.appendChild(LatexWizard);
        VariableElements.appendChild(Open);
        VariableElements.appendChild(Close);
        VariableElements.appendChild(Exit);
        VariableElements.appendChild(Undo);
        VariableElements.appendChild(Redo);
        VariableElements.appendChild(Copy);
        VariableElements.appendChild(Paste);
        VariableElements.appendChild(Cut);
        VariableElements.appendChild(FindReplace);
        VariableElements.appendChild(GoToLine);
        VariableElements.appendChild(ConfigurationMenu);
        VariableElements.appendChild(Customize);
        VariableElements.appendChild(Create);
        VariableElements.appendChild(CustomizeToolbars);
        VariableElements.appendChild(TemplateCreatorWizard);
        VariableElements.appendChild(Bold);
        VariableElements.appendChild(Italic);
        VariableElements.appendChild(Underline);
        VariableElements.appendChild(FootNote);
        VariableElements.appendChild(HyperLink);
        VariableElements.appendChild(AlignLeft);
        VariableElements.appendChild(AlignRight);
        VariableElements.appendChild(AlignCenter);
        VariableElements.appendChild(CommentIn);
        VariableElements.appendChild(CommentOut);
        VariableElements.appendChild(CreateToolbar);
        VariableElements.appendChild(ConvertTo);
        VariableElements.appendChild(Preview);
        VariableElements.appendChild(PreviewSelected);
        VariableElements.appendChild(Output);
        VariableElements.appendChild(CreateNewFile);
        VariableElements.appendChild(OpenWizardMenu);
        VariableElements.appendChild(OpenExistingFile);
        VariableElements.appendChild(CopySelection);
        VariableElements.appendChild(CutSelection);
        VariableElements.appendChild(SetMiktexPath);
    	VariableElements.appendChild(SaveAndExit);
    	VariableElements.appendChild(Cancel);
    	VariableElements.appendChild(MiktexPath);
    	VariableElements.appendChild(EnableOnTheFlyCompilation);
    	VariableElements.appendChild(LanguageSelection);
    	VariableElements.appendChild(Yes);
    	VariableElements.appendChild(No);
    	VariableElements.appendChild(GoTo);
    	VariableElements.appendChild(LineNumber);
    	VariableElements.appendChild(ActionButtonName);
    	VariableElements.appendChild(ToolTip);
    	VariableElements.appendChild(Prefix);
    	VariableElements.appendChild(Suffix);
    	VariableElements.appendChild(ExampleCommand);
    	VariableElements.appendChild(ActionButtonConfiguration);
    	VariableElements.appendChild(Add);
    	VariableElements.appendChild(FindNext);
    	VariableElements.appendChild(Replace);
    	VariableElements.appendChild(ReplaceAll);
    	VariableElements.appendChild(FindWhat);
    	VariableElements.appendChild(ReplaceWith);
    	VariableElements.appendChild(Direction);
    	VariableElements.appendChild(Up);
    	VariableElements.appendChild(Down);
    	VariableElements.appendChild(Import);
    	VariableElements.appendChild(Export);
    	VariableElements.appendChild(ExportDialogTittle1);
    	VariableElements.appendChild(ExportDialogTittle2);
    	VariableElements.appendChild(ImportDialogTittle);
    	VariableElements.appendChild(NoProposals);
    	VariableElements.appendChild(Info);
    	VariableElements.appendChild(ToolbarImported);        
                
        Variables.appendChild(VariableElements);
        domDoc.appendChild(Variables) ;
        
        String xmlString = XmlHandler.createXmlString(domDoc) ;

        try {
			FileWriter fw = new FileWriter(new File("lang\\English.xml"));
			fw.write(xmlString);
			fw.flush();
			fw.close();
		} catch (IOException ex) {
			Logger.getLogger(AppConfigReader.class.getName()).log(Level.SEVERE,
					null, ex);
    	}
		
    }
	
}
